﻿using System;

namespace DimensionsHelper.Common.Metadata;

public readonly struct MetadataContextKey : IEquatable<MetadataContextKey>
{
    private MetadataContextKey(string context, string name)
    {
        Context = context.ToUpper();
        Name = name.ToUpper();
    }


    private string Context { get; }


    private string Name { get; }


    public static MetadataContextKey Create(string context, string name)
    {
        return new MetadataContextKey(context, name);
    }


    public bool Equals(MetadataContextKey other)
    {
        return other.Context.Equals(Context, StringComparison.OrdinalIgnoreCase)
               && other.Name.Equals(Name, StringComparison.OrdinalIgnoreCase);
    }

    public override bool Equals(object? obj)
    {
        return obj is MetadataContextKey key && Equals(key);
    }


    public static bool operator ==(MetadataContextKey left, MetadataContextKey right)
    {
        return left.Equals(right);
    }


    public static bool operator !=(MetadataContextKey left, MetadataContextKey right)
    {
        return !(left == right);
    }

    public override int GetHashCode()
    {
        return HashCode.Combine(Context, Name);
    }
}